# //******************************************************************
# //
# // Copyright 2015 Samsung Electronics All Rights Reserved.
# //
# //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# //
# // Licensed under the Apache License, Version 2.0 (the "License");
# // you may not use this file except in compliance with the License.
# // You may obtain a copy of the License at
# //
# //      http://www.apache.org/licenses/LICENSE-2.0
# //
# // Unless required by applicable law or agreed to in writing, software
# // distributed under the License is distributed on an "AS IS" BASIS,
# // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# // See the License for the specific language governing permissions and
# // limitations under the License.
# //
# //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#

Import('env')

provisioning_env = env.Clone()
root_dir = './../../../../'

######################################################################
# Build flags
######################################################################
provisioning_env.AppendUnique(CPPPATH = [
		'../../stack/include',
		'../../stack/include/internal',
		'../../ocrandom/include',
		'../../logger/include',
		'../../../oc_logger/include',
		'../../ocmalloc/include',
		'include',
		'include/internal',
		'include/oxm',
		'../../resource/csdk/security/include',
		'../../../../extlibs/cjson/',
		'../../../../../extlibs/tinydtls/',
		'../../connectivity/inc',
		'../../connectivity/external/inc',
		'../../connectivity/common/inc',
		'../../connectivity/lib/libcoap-4.1.1',
		'../../connectivity/api',
		'../include',
		'../include/internal',
		'../../../../extlibs/sqlite3',
 		'../../../../extlibs/tinydtls/ecc',
 		'../../../../extlibs/tinydtls/sha2',
 		'../../../../extlibs/asn1cert',
		'ck_manager/include'
		])
target_os = env.get('TARGET_OS')
provisioning_env.AppendUnique(CFLAGS = ['-D__WITH_DTLS__'])
provisioning_env.AppendUnique(CFLAGS = ['-std=c99'])
if target_os not in ['windows', 'winrt']:
	provisioning_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread', '-D__WITH_DTLS__'])

	# Note: 'pthread' is in libc for android. On other platform, if use
	# new gcc(>4.9?) it isn't required, otherwise, it's required
	if target_os != 'android':
		provisioning_env.AppendUnique(LIBS = ['-lpthread'])


provisioning_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
provisioning_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'coap'])

provisioning_env.AppendUnique(LIBS = ['tinydtls'])

if env.get('DTLS_WITH_X509') == '1':
	provisioning_env.AppendUnique(LIBS = ['CKManger'])

provisioning_env.ParseConfig('pkg-config --libs glib-2.0');

if target_os == 'android':
	provisioning_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
	provisioning_env.AppendUnique(LIBS = ['gnustl_static'])

	if not env.get('RELEASE'):
		provisioning_env.AppendUnique(LIBS = ['log'])

if target_os in ['darwin', 'ios']:
	provisioning_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])

######################################################################
# Source files and Targets
######################################################################
provisioning_src = [
	'src/pmutility.c',
	'src/credentialgenerator.c',
	'src/ownershiptransfermanager.c',
	'src/secureresourceprovider.c',
	'src/ocprovisioningmanager.c',
	'src/oxmjustworks.c',
	'src/oxmrandompin.c',
	'src/provisioningdatabasemanager.c',
	root_dir+'/extlibs/sqlite3/sqlite3.c' ]
provisioningserver = provisioning_env.StaticLibrary('ocpmapi', provisioning_src)

provisioning_env.InstallTarget(provisioningserver, 'libocpmapi')
provisioning_env.UserInstallTargetLib(provisioningserver, 'libocpmapi')

if env.get('DTLS_WITH_X509') == '1':
	SConscript('ck_manager/SConscript')

if target_os in ['linux']:
	SConscript('sample/SConscript')

